/*     */ package com.yc.image;
/*     */ 
/*     */ import java.awt.Color;
/*     */ import java.awt.Font;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.image.BufferedImage;
/*     */ import java.io.IOException;
/*     */ import java.util.Random;
/*     */ import javax.imageio.ImageIO;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ 
/*     */ public class ImgServlet extends HttpServlet
/*     */ {
/*  20 */   private Font mFont = new Font("Arial Black", 0, 16);
/*     */ 
/*     */   public void init() throws ServletException
/*     */   {
/*  24 */     super.init();
/*     */   }
/*     */ 
/*     */   Color getRandColor(int fc, int bc) {
/*  28 */     Random random = new Random();
/*  29 */     if (fc > 255)
/*  30 */       fc = 255;
/*  31 */     if (bc > 255)
/*  32 */       bc = 255;
/*  33 */     int r = fc + random.nextInt(bc - fc);
/*  34 */     int g = fc + random.nextInt(bc - fc);
/*  35 */     int b = fc + random.nextInt(bc - fc);
/*  36 */     return new Color(r, g, b);
/*     */   }
/*     */ 
/*     */   private String getRandomChar() {
/*  40 */     int rand = (int)Math.round(Math.random() * 2.0D);
/*  41 */     long itmp = 0L;
/*  42 */     char ctmp = '\000';
/*     */ 
/*  60 */     itmp = Math.round(Math.random() * 9.0D);
/*  61 */     return String.valueOf(itmp);
/*     */   }
/*     */ 
/*     */   protected void service(HttpServletRequest req, HttpServletResponse resp)
/*     */     throws ServletException, IOException
/*     */   {
/*  69 */     resp.setHeader("Pragma", "No-cache");
/*  70 */     resp.setHeader("Cache-Control", "no-cache");
/*  71 */     resp.setDateHeader("Expires", 0L);
/*  72 */     resp.setContentType("image/jpeg");
/*     */ 
/*  74 */     int width = 80; int height = 18;
/*     */ 
/*  76 */     BufferedImage image = new BufferedImage(width, height, 
/*  77 */       1);
/*     */ 
/*  79 */     Graphics g = image.getGraphics();
/*  80 */     Random random = new Random();
/*  81 */     g.setColor(getRandColor(200, 250));
/*  82 */     g.fillRect(1, 1, width - 1, height - 1);
/*  83 */     g.setColor(new Color(102, 102, 102));
/*  84 */     g.drawRect(0, 0, width - 1, height - 1);
/*  85 */     g.setFont(this.mFont);
/*     */ 
/*  87 */     g.setColor(getRandColor(160, 200));
/*  88 */     for (int i = 0; i < 155; i++) {
/*  89 */       int x = random.nextInt(width - 1);
/*  90 */       int y = random.nextInt(height - 1);
/*  91 */       int x1 = random.nextInt(6) + 1;
/*  92 */       int y1 = random.nextInt(12) + 1;
/*  93 */       g.drawLine(x, y, x + x1, y + y1);
/*     */     }
/*     */ 
/*  96 */     for (int i = 0; i < 70; i++) {
/*  97 */       int x = random.nextInt(width - 1);
/*  98 */       int y = random.nextInt(height - 1);
/*  99 */       int x1 = random.nextInt(12) + 1;
/* 100 */       int y1 = random.nextInt(6) + 1;
/* 101 */       g.drawRect(x, y, x + x1, y + y1);
/*     */     }
/*     */ 
/* 104 */     String sRand = "";
/* 105 */     for (int i = 0; i < 4; i++)
/*     */     {
/* 107 */       String tmp = getRandomChar();
/* 108 */       sRand = sRand + tmp;
/*     */ 
/* 110 */       g.setColor(new Color(20 + random.nextInt(110), 20 + 
/* 111 */         random.nextInt(110), 20 + random.nextInt(110)));
/* 112 */       g.drawString(tmp, 15 * i + 10, 15);
/*     */     }
/*     */ 
/* 115 */     HttpSession session = req.getSession(true);
/*     */ 
/* 117 */     session.setAttribute("rand", sRand);
/* 118 */     g.dispose();
/*     */ 
/* 120 */     ImageIO.write(image, "JPEG", resp.getOutputStream());
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.image.ImgServlet
 * JD-Core Version:    0.6.2
 */